﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Data.Model;
using NHibernate;
using DotNet.Common.NHibernateUtil;
using ZLCMS.Business.DwzFrame;

namespace ZLCMS.Web.SystemManage.Template.Template
{
    public partial class ParamConfig : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                paramGrid.Columns.Add(new ListItem() { Text = "参数代码", Value = "ParamCode" });
                paramGrid.Columns.Add(new ListItem() { Text = "参数名", Value = "ParamName" });
                paramGrid.Columns.Add(new ListItem() { Text = "参数值", Value = "ParamValue" });



                int uid = Int32.Parse(Request["uid"]);
                CmsTemplateInfo temp = null;
                using (ISession session = SessionFactoryHelper.CreateSession())
                {
                    temp = session.Get<CmsTemplateInfo>(uid);
                    ViewState["uid"] = uid;
                }
                paramGrid.Value = temp.Params;
            }
            else
            {
                int uid = ViewState["uid"] == null ? 0 : (int)ViewState["uid"];


                using (ISession session = SessionFactoryHelper.CreateSession())
                {
                    CmsTemplateInfo temp = session.Get<CmsTemplateInfo>(uid);
                    
                    temp.Params = paramGrid.Value;
                    session.SaveOrUpdate(temp);
                    session.Flush();
                }

                FrameHelper _framePage = new FrameHelper(this);
                ReturnCode rc = new ReturnCode()
                {
                    message = "操作成功"
                };

                rc.callbackType = "forward";
                rc.forwardUrl = "/SystemManage/Template/Template/ParamConfig.aspx?tabid=ParamConfig";

                //if (Request["submit_op"] != "1")
                {
                    rc.forwardUrl += "&uid=" + uid;
                }

                _framePage.Alert(rc);

            }


        }
    }
}